﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace FacebookTestUserManager
{
    public partial class NewUserWindow : Window
    {

        public string AccessToken { set; get; }
        public string AppId { set; get; }

        public NewUserWindow()
        {
            InitializeComponent();
            this.Loaded += new RoutedEventHandler(NewUserWindow_Loaded);
        }

        void NewUserWindow_Loaded(object sender, RoutedEventArgs e)
        {
            var userNumbers = new List<int>();
            for (var i = 0; i < 100; i++)
                userNumbers.Add(i+1);

            this.userNumber.DataContext = userNumbers;

            var userPermissions = Enum.GetNames(typeof(UserPermissions));
            this.userPermissionsList.ItemsSource = userPermissions;

            var friendPermissions = Enum.GetNames(typeof(FriendPermissions));
            this.friendPermissionsList.ItemsSource = friendPermissions;
        }

        private void Save_Click(object sender, RoutedEventArgs e)
        {
            int number = (int)this.userNumber.SelectedValue;

            for (int i = 0; i < number; i++)
            {

                var installed = this.Installed.IsChecked.GetValueOrDefault(false);

                var userPermissions = new List<UserPermissions>();
                foreach (string item in this.userPermissionsList.SelectedItems)
                {
                    userPermissions.Add((UserPermissions)Enum.Parse(typeof(UserPermissions), item));
                }

                var friendPermissions = new List<FriendPermissions>();
                foreach (string item in this.friendPermissionsList.SelectedItems)
                {
                    friendPermissions.Add((FriendPermissions)Enum.Parse(typeof(FriendPermissions), item));
                }

                var helper = new FacebookHelper(this.AppId, this.AccessToken);

                var result = helper.CreateTestUser(installed, userPermissions, friendPermissions);
            }

            this.Close();
        }
    }
}
